using System;
using flickr.api;
using flickr.api.communication;
using FUser = flickr.api.User;
using System.Drawing;

namespace FlickrShots.Framework
{
	public class User
	{
		private FUser _flickrUser;

		public static readonly User NullUser = new User();

	    internal User() {}
	    
	    internal User(Auth.AuthUser authUser)
	    {
	        _flickrUser = new FUser(Flickr.Connection);
	        
	        _flickrUser.ID = authUser.ID;
	        _flickrUser.Name = authUser.Name;
	    }
	    
		internal User(FUser user)
		{
		    _flickrUser = user;
		}

		public string ID
		{
			get { return _flickrUser != null ? _flickrUser.ID : null; }
            set { _flickrUser.ID = value; }
		}

		public string Name
		{
			get { return _flickrUser != null ? _flickrUser.Name : null; }
            set { _flickrUser.Name = value; }
		}

        public string Link
        {
            get { return Flickr.People.getInfo(ID).ProfileUrl; }
        }

	    public PhotoCollection GetContactPhotoCollection()
	    {
	        throw new NotImplementedException();
	    }

	    public PhotoCollection GetPhotoCollection()
	    {
	        return Flickr.People.getPublicPhotos(ID).PhotoCollection;
	    }

	    public Image BuddyIcon
	    {
	        get
	        {
	            int iconServer = Flickr.People.getInfo(ID).IconServer;
	            return
	                Flickr.Connection.DownloadImageFromUrl(
	                    string.Format("http://static.flickr.com/{0}/buddyicons/{1}.jpg", iconServer, ID));
	        }
	    }
	}
}
